<div style="margin:10px;">
    <form class="layui-form" id="groupForm" method="post" action="/group/edit.do">
        <input type="hidden" name="id" required lay-verify="required"  value=""/>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" required lay-verify="required" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" lay-skin="switch" value="1" lay-text="正常|锁定">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['jquery', 'form'], function () {
        var form = layui.form;
        var $ = layui.$;
        // 生成随机 formID
        // 生成随机 submitBtnId

        console.log($('#groupForm input').length);

        // 获取数据
        $.get('/group/edit.do?id=' + BMS.cache.param.group['id'], function(resp){
            var data = resp.data;
            $('#groupForm input').each(function(index, ele) {
                console.log(ele)
                var $ele = $(ele);
                var type = $ele.attr('type');
                if ('text' == type || 'hidden' == type)
                    $ele.val(data[$ele.attr('name')]);
                else if ('checkbox' == type && $ele.val() == 1)
                    $ele.attr('checked', 'checked');
            })

            form.render();

            //监听提交
            form.on('submit(demo1)', function(data){
                $.post('/group/edit.do', data.field, function(resp)
                {
                    layer.alert(JSON.stringify(data.field), {
                        title: '最终的提交信息'
                    })
                })

                return false;
            });
        })
    })
</script>